cd "~/Documents/pvs-heroku"

// Ratings at rating level
insheet using "sig_ratings.csv", clear
duplicates drop *, force
reshape wide rating, i(candidateid) j(sig_id)
tempfile ratings
save `ratings'

// Votes at vote level
insheet using "votes.csv", clear
replace action = "1" if action == "Yea"
replace action = "0" if action == "Nay"
destring action, replace force
duplicates drop action candidateid vote_id, force
rename action vote
reshape wide vote, i(candidateid) j(vote_id)
tempfile votes
save `votes'

// House members
insheet using "all_house_members.csv", clear
merge 1:m candidateid using `votes', nogen keep(1 3)
merge 1:m candidateid using `ratings', nogen keep(1 3)

nmissing rating*

// Count number of eligible votes
gen nvotes = 0
foreach var of varlist vote* {
	replace nvotes = nvotes + 1 if !missing(`var')
}

// Count number of eligible ratings
gen nratings = 0
foreach var of varlist rating* {
	replace nratings = nratings + 1 if !missing(`var')
}

// Compute other MC-level vars
gen partyoneletter = substr(officeparties, 1, 1)
gen partylong = "Democrat" if partyone == "D"
replace partylong = "Republican" if partyone == "R"
gen longname = "Representative " + firstname + " " + lastname + " (" + partylong + ")"
gen shortname = "Rep. " + lastname + " (" + partyoneletter + ")"

outsheet using "processed_MCs_for_api.csv", comma replace

/*
// Senators -- don't have their votes basically
insheet using "all_senators.csv", clear
merge 1:m candidateid using `votes', nogen keep(1 3)
nmissing action*
